﻿using ETA.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Http;

namespace ETA.WebAPI.App_Start
{
    public class TokenAuthenticationAttribute : System.Web.Http.Filters.ActionFilterAttribute
    {
        public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
        {
            //var authToken = HttpContext.Current.Request.Headers["AuthToken"];
            var authToken = HttpContext.Current.Request.QueryString["authToken"];
            var key = Config.WebApiToken;
            if (string.IsNullOrEmpty(authToken)||authToken!=key)
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }
        }
    }
}